{extend name="public:base"/}


{block name="title"}新增优惠劵{/block}
{block name="style"}{/block}

{block name="main"}

<section class="content" xmlns="http://www.w3.org/1999/html">
    <div class="row">

        <div class="col-md-12">

            <div class="row">
                <div class="col-lg-12">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title">新增优惠劵</h3>
                        </div>
                        <form  id="pt_form" method="post">
                            <div class="box-body">

                                <div class="clearfix"></div>

     
                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label for="name" class="control-label Validform_label" >优惠券名称</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="name" class="form-control" name="name" placeholder="请输入优惠券名称" datatype="s2-50"  errormsg="优惠券名称超出长度范围">
                                        <div class="help-block"></div>
                                    </div>
                                </div>
          
                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label for="money" class="control-label Validform_label" >优惠券面额</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="money" class="form-control" name="money" placeholder="请输入优惠券面额" datatype="n">
                                        <div class="help-block"></div>
                                    </div>
                                </div>
          
                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label for="condition" class="control-label Validform_label" >消费金额</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="condition" class="form-control" name="condition" placeholder="请输入消费金额" datatype="n" >
                                        <div class="help-block"></div>
                                    </div>
                                </div>
          
                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label for="create_num" class="control-label Validform_label" >发放数量</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="create_num" class="form-control" name="create_num" placeholder="请输入发放数量" datatype="n"  errormsg="发放数量是数字类型">
                                        <div class="help-block"></div>
                                    </div>
                                </div>
          
                                <div class="form-group required" >
                                    <div class="col-sm-2 text-right">
                                        <label class="control-label Validform_label">状态                                                            </label>
                                    </div>

                                    <div class="col-sm-10">
                                        <div>
                                            <span style="color:#636f7a"><input type="radio" name="status" value="1" >有效</span>

                                            
                                            <span style="color:#636f7a"><input type="radio" name="status" value="0" datatype="*" nullmsg="请选择状态：0无效，1有效" checked="checked">无效</span>
                                        </div>
                                        <div class="help-block"></div>
                                    </div>
                                </div>
                                <!--
                                <div class="form-group required" >
                                    <div class="col-sm-2 text-right">
                                        <label class="control-label Validform_label">选择商品                                                     </label>
                                    </div>

                                    <div class="col-sm-10">
                                        <div>
                                            <span style="color:#636f7a"><input type="radio" name="select_goods" value="0" checked="checked" >所有商品</span>


                                            <span style="color:#636f7a"><input type="radio" name="select_goods" value="1" datatype="*" nullmsg="请选择状态：0无效，1有效" >部分商品</span>
                                        </div>
                                        <div class="help-block"></div>

                                        <input type="hidden" name="select_goods_id" id="select_goods_id" />

                                        <div class="goods_list" style="display:none;">
                                            <div class="m-t-sm"></div>
                                            <div class="search" style="height:34px;">
                                                <div class="col-sm-3">
                                                    <div class="form-row">
                                                    <span class="input-group-btn">
                                                        <button type="button"  onclick="selectGoods();" class="btn btn-white"><i class="fa fa-search"></i> 选择商品</button>
                                                    </span>
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="m-t-sm"></div>

                                            <table class="table table-hover" >
                                                <thead>
                                                    <th>
                                                        商品名称
                                                    </th>
                                                    <th>
                                                        商品图片
                                                    </th>
                                                    <th>
                                                        图号
                                                    </th>
                                                    <th>
                                                        价格
                                                    </th>
                                                    <th>
                                                        库存
                                                    </th>
                                                    <th>操作</th>
                                                </thead>
                                                <tbody id="goods_list_td">
                                                    <tr>
                                                        <td>324</td>
                                                        <td>324</td>
                                                        <td>324</td>
                                                        <td>324</td>
                                                        <td>324</td>
                                                        <td><button type="button" class="btn btn-danger btn-xs" title="删除">删除</button></td>
                                                    </tr>
                                                </tbody>
                                            </table>

                                        </div>
                                    </div>
                                </div>

                                -->
                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label for="use_start_time" class="control-label Validform_label" >使用起始日期</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="use_start_time" class="form-control" name="use_start_time" placeholder="使用起始日期" datatype="*"  nullmsg="使用起始日期不能为空">
                                        <div class="help-block"></div>
                                    </div>
                                </div>

                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label for="use_end_time" class="control-label Validform_label" >使用结束日期</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="use_end_time" class="form-control" name="use_end_time" placeholder="使用结束日期" datatype="*"  nullmsg="使用结束日期不能为空">
                                        <div class="help-block"></div>
                                    </div>
                                </div>
                                 </div>
                            <div class="box-footer text-center">
                                <button class="btn btn-primary" type="submit">保存</button>
                                <span class="btn btn-white" onclick="history.go(-1)">返回</span>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
{/block}

{block name="js"}
<script>
    var validate = validator('#pt_form');


    window.datetimepicker_648a00bd = {"bootcssVer":3,"minView":"month","icontype":"glyphicon","fontAwesome":false,"icons":{"leftArrow":"glyphicon-arrow-left","rightArrow":"glyphicon-arrow-right"},"format":"yyyy-mm-dd","todayHighlight":true,"autoclose":true,"todayBtn":true,"timezone":"Asia\/Shanghai","language":"zh-CN"};
    jQuery('#use_start_time').datetimepicker(datetimepicker_648a00bd);
    jQuery('#use_end_time').datetimepicker(datetimepicker_648a00bd);

</script>
<script>
    /*
    $('input[name="select_goods"]').click(function(){
        if($(this).val() == 1){
            getGoods();
        }
    });

    function getGoods(goods_name='',p=1){
        $.ajax({
            url:"<?=url('seller/coupon/ajaxGetGoods')?>",
            type:'post',
            dataType:'json',
            success:function(res){
                let str = '';
                if(res.data.length>0){
                    $(res.data).each(function(k,v){
                        str += '<tr>';
                        str += '<td>'+v.goods_name+'</td>';
                        str += '<td><img style="width:80px;height:80px;" src="/'+v.original_img+'"></td>';
                        str += '<td>'+v.figure_nu+'</td>';
                        str += '<td>'+v.shop_price+'</td>';
                        str += '<td>'+v.store_count+'</td>';
                        str += '<td><button type="button" class="btn btn-primary btn-xs" title="参与活动" onclick="joinActive('+v.goods_id+',this)">参与活动</button></td>';
                        str += '</tr>';
                    });
                    $('#goods_list_td').html(str);
                }
            }
        });
    }


    $('input[name="select_goods"]').click(function(){
        if($(this).val() == 1){
            $('.goods_list').css('display','block');
        }else{
            $('.goods_list').css('display','none');
        }
    });

    Array.prototype.remove = function(val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };

    let goods_list = [];
    function joinActive(goods_id,obj){
        if(!goods_id){
            return false;
        }
        if($(obj).hasClass('btn-primary')){
            $(obj).removeClass('btn-primary').addClass('btn-danger');
            $(obj).text('取消活动');
            if(goods_list.indexOf(goods_id) == -1){
                goods_list.push(goods_id);
            }
        }else{
            $(obj).removeClass('btn-danger').addClass('btn-primary');
            $(obj).text('参与活动');
            $(obj).parent().parent().remove();
            goods_list.remove(goods_id);
        }

        $('#select_goods_id').val(goods_list);
        //console.log(goods_list);
    }

    $('#goods_list_td').html('');

    function selectGoods(){
        layer.open({
            type: 2,
            content: "<?=url('seller/goods/getGoodsList')?>",
            area:['1000px','500px'],
            success: function(layero, index){
                var body = layer.getChildFrame('body', index);
                var select_input = null;
                var iframeWin = window[layero.find('iframe')[0]['name']];
                //console.log(body.html()) //得到iframe页的body内容
                //body.find('input').val('Hi，我是从父页来的')
                select_input = body.find("input[name='select_goods_id']");
            },

            btn: ['确定', '取消'],
            yes:function(index){
               //var body = layer.getChildFrame('body');
               // let input= body.find(".select_goods_id").html();

                //let input = $("input[name='select_goods_id']:checked");
                //console.log(select_input);
                //layer.msg(input);
                var body = layer.getChildFrame('body', index);
                var select_input = null;
                //var iframeWin = window[body.find('iframe')[0]['name']];
                //console.log(body.html()) //得到iframe页的body内容
                //body.find('input').val('Hi，我是从父页来的')
                select_input = body.find("input[name='select_goods_id']:checked");
                if(select_input.length == 0){
                    layer.msg('请选择商品');
                    return false;
                }

                let goods = select_input.data('goods');
                let str = '';
                if(goods_list.indexOf(goods.goods_id) == -1){
                    goods_list.push(goods.goods_id);
                    str += '<tr>';
                    str += '<td>'+goods.goods_name+'</td>';
                    str += '<td><img style="width:80px;height:80px;" src="/'+goods.original_img+'"></td>';
                    str += '<td>'+goods.figure_nu+'</td>';
                    str += '<td>'+goods.shop_price+'</td>';
                    str += '<td>'+goods.store_count+'</td>';
                    str += '<td><button type="button" class="btn btn-danger btn-xs" title="参与活动" onclick="joinActive('+goods.goods_id+',this)">删除</button></td>';
                    str += '<input type="hidden" name="goods_ids[]" value="'+goods.goods_id+'">';
                    str += '</tr>';
                    $('#goods_list_td').append(str);
                    $('#select_goods_id').val(goods_list);
                }
                layer.closeAll();
            }
        })
    }
    */
</script>
{/block}